﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using BLToolkit.DataAccess;
using BLToolkit.Common;
using BLToolkit.Data.Linq;
using BLToolkit.Mapping;

namespace Core
{
    [TableName("tblKiLuat")]
    public class KyLuat
    {
        [PrimaryKey, Identity]
        [MapField("MaKiLuat")]
        public int ID { get; set; }
        
        public string MucKiLuat{ get; set; }
        public string MoTa { get; set; }
        public static IQueryable<KyLuat> KyLuats
        {
            get
            {
                using (var db = new DataContext())
                {
                    return db.GetTable<KyLuat>();
                }
            }
        }
        public static List<KyLuat> All()
        {
            return KyLuats.ToList();
        }
        public static KyLuat Single(int id)
        {
            return KyLuats.SingleOrDefault(x => x.ID == id);
        }
        public static int Add(KyLuat entity)
        {
            using (var db = new DataContext())
            {
                object rs = db.InsertWithIdentity(entity);
                return int.Parse(rs.ToString());
            }
        }
        public static int Update(KyLuat entity)
        {
            using (var db = new DataContext())
            {
                return db.Update(entity);
            }
        }
        public static int Delete(int id)
        {
            return KyLuats.Delete(x => x.ID == id);
        }
    }
}
